ALTER TABLE SIGIN.DOCUMENTOBORRADO
 DROP PRIMARY KEY CASCADE;
DROP TABLE SIGIN.DOCUMENTOBORRADO CASCADE CONSTRAINTS;

CREATE TABLE SIGIN.DOCUMENTOBORRADO
(
  IDDOCUMENTOBORRADO  NUMBER                    NOT NULL,
  TIPO                CHAR(1)                   NOT NULL,
  IDPERSONA           NUMBER                    NOT NULL,
  FECHAHORA           DATE                      NOT NULL,
  IDELEMENTO          NUMBER                    NOT NULL,
  NOMBRE              VARCHAR2(255)             NOT NULL,
  DATOBUSQUEDA        VARCHAR2(4000)            NOT NULL,
  DATOINSERT          VARCHAR2(4000)            NOT NULL
)
LOGGING 
NOCACHE
NOPARALLEL;


CREATE UNIQUE INDEX SIGIN.PK_DOCUMENTOBORRADO ON SIGIN.DOCUMENTOBORRADO
(IDDOCUMENTOBORRADO)
LOGGING
NOPARALLEL;


CREATE OR REPLACE TRIGGER SIGIN.SET_DOCUMENTOBORRADO_ID
   BEFORE INSERT
   ON DOCUMENTOBORRADO
   REFERENCING NEW AS NEW OLD AS OLD
   FOR EACH ROW
DECLARE
   tmpvar   NUMBER;
BEGIN
   tmpvar := 0;

   SELECT DOCUMENTOBORRADO_SEQ.NEXTVAL
     INTO tmpvar
     FROM DUAL;

   :NEW.iddocumentoborrado := tmpvar;
END SET_DOCUMENTOBORRADO_ID;
/
SHOW ERRORS;

ALTER TRIGGER SIGIN.SET_DOCUMENTOBORRADO_ID DISABLE;



ALTER TABLE SIGIN.DOCUMENTOBORRADO ADD (
  CONSTRAINT PK_DOCUMENTOBORRADO
 PRIMARY KEY
 (IDDOCUMENTOBORRADO));


ALTER TABLE SIGIN.DOCUMENTOBORRADO ADD (
  CONSTRAINT FK_DOCUMENTOBORRADO_PERSONA 
 FOREIGN KEY (IDPERSONA) 
 REFERENCES SIGIN.PERSONAS (IDPERSONA));